package com.guanyong.services;

import com.guanyong.dao.IVideoBarrageDaoMapper;
import com.guanyong.model.VideoBarrageModel;
import com.guanyong.utils.Comm.ResultCode;
import com.guanyong.utils.Comm.ResultObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * Created by mxk on 2017/7/5.
 */

@Service
public class VideoBarrageService {

    @Autowired
    IVideoBarrageDaoMapper iVideoBarrageDaoMapper;

    public ResultObject<Integer> AddVideoBarrage(VideoBarrageModel videoBarrageModel){
        ResultObject<Integer> resultObject=new ResultObject<Integer>();
        Integer res=iVideoBarrageDaoMapper.insert(videoBarrageModel);
        if (res>-1){
            resultObject.setCode(ResultCode.OperateOk);
        }
        else{
            resultObject.setCode(ResultCode.OperateFail);
        }
        return  resultObject;
    }

    public List<VideoBarrageModel> GetVideoBarrage(Integer classtype,String objectid,String btime){
        SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
        ParsePosition pos = new ParsePosition(0);
        Date strtodate = formatter.parse(btime, pos);

        Calendar nowTime = Calendar.getInstance();
        nowTime.setTime(strtodate);
        nowTime.add(Calendar.MINUTE, 10);

        String edateTime=formatter.format(nowTime.getTime());


        return iVideoBarrageDaoMapper.GetVideoBarrageModelList
                (classtype,objectid,btime,edateTime);
    }
}
